//
//  ZCTabBar.swift
//  weibo
//
//  Created by 张城 on 16/7/19.
//  Copyright © 2016年 张城. All rights reserved.
//

import UIKit
import SnapKit

class ZCTabBar: UITabBar {

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var addBut: UIButton = {
        let button = UIButton()
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: .Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: .Highlighted)
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: .Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: .Highlighted)
        button.addTarget(self, action: #selector(ZCTabBar.addclick), forControlEvents: .TouchUpInside)
        button.sizeToFit()
        return button
    }()
    
    var callback:(()->())?
    
    func addclick() {
        callback?()
//        print("35354645rer")
    }
    
    func setupUI() {
        addSubview(addBut)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        addBut.snp_makeConstraints { (make) in
            make.center.equalTo(self)
            
            let butW = frame.width*0.2
            var index: CGFloat = 0
            
            for but in subviews {
                
                if but .isKindOfClass(NSClassFromString("UITabBarButton")!) {
                   
                    but.frame.origin.x = index * butW
                    but.frame.size.width = butW
                    index++
                    
                    if index == 2 {
                        index++
                    }
                }
            }
        }
    }
    
    
    

}
